package com.example.projectmanagement.repository.study;

import com.example.projectmanagement.model.study.QuestionLike;
import com.example.projectmanagement.model.study.Question;
import com.example.projectmanagement.model.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.Optional;

@Repository
public interface QuestionLikeRepository extends JpaRepository<QuestionLike, Long> {
    Optional<QuestionLike> findByQuestionAndUser(Question question, User user);
    
    @Query("SELECT COUNT(ql) FROM QuestionLike ql WHERE ql.question.id = :questionId")
    Integer countByQuestionId(@Param("questionId") Long questionId);
    
    void deleteByQuestion(Question question);
}